/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: key_value_storage.h
 *
 * Purpose: key value storage(persistency) implementation for base library
 *
 * Developer:
 *   wen.gu , 2019-10-11
 *
 * TODO:
 *
 ***************************************************************************/

/******************************************************************************
 **    INCLUDES
 ******************************************************************************/
#ifndef __PANDA_PER_KEY_VALUE_STORAGE_H__
#define __PANDA_PER_KEY_VALUE_STORAGE_H__

#include <memory>
#include <vector>
#include <string>
#include "panda/core/types.h"

namespace panda
{
namespace per
{
/******************************************************************************
 **    MACROS
 ******************************************************************************/

 /******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/


using KeyArray = std::vector<std::string>;
using KeyType = const std::string;

 /******************************************************************************
 **    CLASSES/FUNCTIONS DEFINITIONS
 ******************************************************************************/

class CORE_CLASS KeyValueStorage
{
public:
    static std::shared_ptr<KeyValueStorage> OpenKeyValueStorage(const std::string& kvs);

public:
    KeyValueStorage(const std::string& kvs);
    ~KeyValueStorage();

public:
    KeyValueStorage(const KeyValueStorage&) = delete;
    KeyValueStorage& operator= (const KeyValueStorage&) = delete;

public:
    KeyArray getAllKeys();
    bool hasKey(KeyType& key);
    bool removeKey(KeyType& key);
    bool removeAllKeys();
    bool reset();
    bool syncToStorage();
public:
    bool getValue(KeyType& key, std::string& val);
    bool getValue(KeyType& key, int8_t& val);
    bool getValue(KeyType& key, int16_t& val);
    bool getValue(KeyType& key, int32_t& val);
    bool getValue(KeyType& key, int64_t& val);
    bool getValue(KeyType& key, uint8_t& val);
    bool getValue(KeyType& key, uint16_t& val);
    bool getValue(KeyType& key, uint32_t& val);
    bool getValue(KeyType& key, uint64_t& val);
    bool getValue(KeyType& key, float& val);
    bool getValue(KeyType& key, double& val);

    bool setValue(KeyType& key, const std::string& val);
    bool setValue(KeyType& key, int8_t val);
    bool setValue(KeyType& key, int16_t val);
    bool setValue(KeyType& key, int32_t val);
    bool setValue(KeyType& key, int64_t val);
    bool setValue(KeyType& key, uint8_t val);
    bool setValue(KeyType& key, uint16_t val);
    bool setValue(KeyType& key, uint32_t val);
    bool setValue(KeyType& key, uint64_t val);
    bool setValue(KeyType& key, float val);
    bool setValue(KeyType& key, double val);

private:
    class impl;
    std::unique_ptr<impl> mImpl;
};


} /** namespace per */
} /** namespace panda*/

#endif /** !__PANDA_PER_KEY_VALUE_STORAGE_H__ */
